package com.rtmanager.data;

public class Ticket {
	private Integer id=0;
	private String owner="";
	private String subject="";
	private String requestors="";
	private String queue="";
	private String creator="";
	private String status="";
	private String created="";
	private TicketHistoryEntry[] tickethistory;
	public String strDebug="";
	
	
	@SuppressWarnings("unused")
	private Ticket() {
		id=0;
		subject="";
		requestors="";
	}
	
	/**
	 * construit un ticket à partir des infos fournies 
	 * 
	 */
	/*public Ticket(String id, String owner, String subject, String requestors,String queue,String creator,String status,String created) {
		this.id = id;
		this.owner = owner;
		this.subject = subject;
		this.requestors = requestors;
		this.queue = queue;
		this.creator = creator;
		this.status = status;
		this.created = created;
	}*/
	
	/**
	 * construit un ticket à partir d'une réponse de rt
	 * @param RTResponse
	 */
	public Ticket( String RTResponse ) {
		String[] lines = RTResponse.split("\n");
		if (lines.length > 1) {
			for(int i=2;i<lines.length;i++) {
				String[] variable = lines[i].split(":");
				/*DEBUG*/
				strDebug+="line :"+lines[i]+"\n";
				strDebug+="variable.length :"+variable.length+"\n";
				/*/DEBUG*/
				if (variable.length > 1) {
					String varName = variable[0];
					String varValue = variable[1];
					/*DEBUG*/
					strDebug+="varName :["+varName+"]\n";
					strDebug+="varValue :["+varValue+"]\n";
					/*/DEBUG*/
					
					/* ID */
					if ( varName.equals("id") ) {
						this.id=new Integer(varValue.split("/")[1]);	
					}
					/* OWNER */
					if (varName.equals("Owner") ) {
						this.owner=varValue;	
					}
					/* SUBJECT */ 
					if (varName.equals("Subject") ) {
						this.subject=varValue;	
					}
					/* REQUESTORS */
					if (varName.equals("Requestors") ) {
						this.requestors=varValue;
					}
					/* QUEUE */
					if (varName.equals("Queue") ) {
						this.queue=varValue;	
					}
					/* CREATOR */
					if (varName.equals("Creator") ) {
						this.creator=varValue;	
					}
					/* STATUS */
					if (varName.equals("Status") ) {
						this.status=varValue;	
					}
					/* CREATED */
					if (varName.equals("Created") ) {
						this.created = varValue;
					}
					
					/*DEBUG*/
					strDebug+= "toString : {" + getId() + "\n"
					+ getOwner() + "\n"
					+ getSubject() + "\n"
					+ getRequestors() + "\n"
					+ getQueue() + "\n"
					+ getCreator() + "\n"
					+ getStatus() + "\n"
					+ getCreated() + "\n"
					+"}\n"; 
					
					/*/DEBUG*/
				}
			}
		}
	}
	
	public Integer getId() {
		return id;
	}
	
	public String getOwner() {
		return owner;
	}
	
	public String getSubject() {
		return subject;
	}
	
	public String getRequestors() {
		return requestors;
	}
	
	public String getQueue() {
		return queue;
	}
	
	public String getCreator() {
		return creator;
	}
	
	public String getStatus() {
		return status;
	}
	
	public String getCreated() {
		return created;
	}

	public void setHistory(TicketHistoryEntry[] ticketHistory) {
		this.tickethistory = ticketHistory;
	}
	
	public String toString() {
		return getId() + "\n"
		+ getOwner() + "\n"
		+ getSubject() + "\n"
		+ getRequestors() + "\n"
		+ getQueue() + "\n"
		+ getCreator() + "\n"
		+ getStatus() + "\n"
		+ getCreated() + "\n"; 
	}
	


}
